<?php
if (!defined('__COLA_DIR__')) exit;

/**
 * 操作按钮组件
 *
 * @author edikud
 * @package Widget
 * @copyright Copyright (c) 2019 Cola (http://www.mcooo.com)
 * @license GNU General Public License 2.0
 */
class Widget_Operate extends Widget
{

    public $map;

    public function render($buttons = array())
    {
		if(null !== $this->map){
			return call_user_func($this->map, $buttons, $this);
		}

		/** 默认javascript (可覆盖或修改) */
		Cola::widget('Widget_Scripts')
		    ->set("
            (function () {
                $(document).ready(function () {			
                    $('.cola-operate').on('click.operate.dropdown', '.cola-operate-button',function() {
                        //$(this).toggleClass(that.config.activeClass);
                        $('.cola-dropdown').toggle();
                        return false;
                    });
					$('.cola-operate').selectAll('[data-selectall]', '.cola-container', '.cola-lists');
					$('.cola-container').selectRow('.cola-lists');
					$('.cola-container').deleteRow('[data-action]', '.cola-container', '.cola-lists');
                });
            })();", 'operate');
		
		return '<div class="cola-operate"><div class="cola-operate-button" data-operate-button>'._t('操作').' <i class="ci-down-dir"></i></div><ul class="cola-dropdown dropdown"><li class="cola-operate-list">'.implode('</li><li class="cola-operate-list">', $buttons).'</li></ul></div>';
    }

}
